<?php

/*

  Action – Reaction	$3

  Draw until you have 6 cards in hand.
  When you gain a card, you may reveal this from your hand. If you do, either trash that card, or put it on top of your deck.

 */

//this card does not implement iReaction for reason, as a reaction it does nothing, unless card gained, for that there is another function.
class WatchTower extends Card implements iAction, iKingdom, iProsperity, iReaction, iReactingCard {

    private $reactConditions;

    public function __construct() {
        parent::__construct("Watchtower", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;

        $this->reactConditions = new ReactionConditions();
        $this->reactConditions->action = array(Gain);
        $this->reactConditions->actor = array(Yourself);
        $this->reactConditions->cardLocation = array(PlayHand);
        $this->reactConditions->limit = OncePerReaction;
    }

    public function getDescription() {
        return array(
            "Draw until you have 6 cards in hand.",
            "When you gain a card, you may reveal this from your hand. If you do, either trash that card, or put it on top of your deck.");
    }

    public function play(Game $game, $isRealCard) {
        $handSize = $game->getPlayHandSize();
        $drawCardsNum = max(0, 6 - $handSize);
        $drawed_cards = $game->drawCards($drawCardsNum);
        ScreenDisplay::addScreenMessage($game, true, "draw " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards) . " cards");
        $game->cardActionFinished();
        return true;
    }

    public function getConditions() {
        return $this->reactConditions;
    }

    public function isReactRelevant(Game $game, $card, $name) {
        return true;
    }

    public function react(Game $game, $card, $name) {
        ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($this), "reveals " . nicePrint($this), $name);

        $watchtower = $game->getCardInHand($this, $name);
        if ($watchtower) {
            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Reveal " . $this->getValue() . "?", $name);
            $answer = $output[0];
            if ($answer == "Yes") {
                $options = array(new Option(1, "Draw deck"), new Option(2, "Trash"));
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Where to put the " . $card->getValue() . "?", $name);
                $answer = $output[0];
                if ($answer == "Draw deck") {
                    $game->setDestinationPile(DrawPile);
                    ScreenDisplay::addScreenMessage($game, true, "put " . nicePrint($card) . " on top of your deck", "puts " . ScreenDisplay::$LMSG . " cards of top of his deck", $name);
                } else {
                    $game->setDestinationPile(Trash);
                    ScreenDisplay::addScreenMessage($game, true, "put " . nicePrint($card) . " in trash", "puts " . ScreenDisplay::$LMSG . " in trash", $name);
                }
            }
        }
        $game->setTempCard($card);
        return true;
    }

}

?>